import requests
import numpy as np
def get_embedding(text):

    url = "https://api.siliconflow.cn/v1/embeddings"

    payload = {
        "model": "BAAI/bge-large-zh-v1.5",
        "input": text,
        "encoding_format": "float"
    }
    headers = {
        "Authorization": "Bearer sk-wdotugwguprsmeimsowcbehipjlkyaabkgbxnudkkhvjhumm",
        "Content-Type": "application/json"
    }

    response = requests.request("POST", url, json=payload, headers=headers)


    # 转化为np数组
    embedding = np.array(response.json()["data"][0]["embedding"])
    return embedding


if __name__ == "__main__":
    text = "Silicon flow embedding online: fast, affordable, and high-quality embedding services. come try it out!"
    print(get_embedding(text))